#include "wartist.h"

WArtist::WArtist(QWidget *parent) :
    WTable(parent)
{
    tableView->setModel(&model);
    tableView->setColumnWidth(DtArtist::Name, 300);
    tableView->setColumnWidth(DtArtist::Play, 30);
    tableView->setColumnWidth(DtArtist::Add, 30);
    tableView->setColumnWidth(DtArtist::Heart, 30);
    connect(tableView, SIGNAL(clicked(QModelIndex)), this,
            SLOT(on_tableView_clicked(QModelIndex)));
}

WArtist::~WArtist()
{
}

void WArtist::setList(QList<AbstractData *> &lArtist)
{
    model.setList((QList<DtArtist *> &)lArtist);
}

QString WArtist::getPath()
{
    return selection;
}

void WArtist::on_tableView_clicked(const QModelIndex &index)
{
    if(!index.isValid())
        return;
    if(index.column() == DtArtist::Name)
    {
        selection = model.getList()[index.row()]->getName();
        emit navigateToAlbums((QList<AbstractData *> &)model.getList()
                              [index.row()]->getAlbums());
    }
    else
    {
        selection = "";
        switch (index.column())
        {
        case DtArtist::Play:
            emit playArtist(model.getList()[index.row()]->getTracks());
            break;
        case DtArtist::Add:
            emit addArtist(model.getList()[index.row()]->getTracks());
            break;
        case DtArtist::Heart:
            break;
        default:
            return;
            break;
        }
        ((MArtist *)index.model())->getList()
                [index.row()]->clicked(index.column());
    }
}

void WArtist::on_tableView_doubleClicked(const QModelIndex &index)
{
    if(!index.isValid())
        return;
    qDebug() << "Double clic on column name";
}
